$(document).ready(function() {
	// 全局页面进入loading
	function pageLoading() {

		var index = layer.load(2, {shade: [0.1,'#fff']});
		setTimeout(function() {
			layer.close(index);
			$('.index, .reserve').css({'opacity': '1'});
		},1000);

	}pageLoading();
	
	// 点击回到底部
	$('.return-bottom').click(function(){$('html,body').animate({scrollTop: $('.index').height()}, 1000);});

	$('.enroll-btn').click(function() {
		window.location.href = 'reserve.php'
	});

	// 分享框关闭
	$('.close-btn').on('click', function(){
		$('.share-wrap').fadeOut();
	});

	// 分享框开启
	$('.share_img').on('click', function(){
		$('.share-wrap').fadeIn();
	});
	
    // 截止时间毫秒数
    var endTime = (new Date("2017/10/22 23:59:59")).getTime();
    //当前时间毫秒数
    var currentTime = (new Date()).getTime();
    //倒计时总秒数量
    var intDiff = parseInt((endTime-currentTime)/1000);
	function timer(intDiff){
		window.setInterval(function(){
		var day=0,
			hour=0,
			minute=0,
			second=0;//时间默认值		
		if(intDiff > 0){
			day = Math.floor(intDiff / (60 * 60 * 24));
			hour = Math.floor(intDiff / (60 * 60)) - (day * 24);
			minute = Math.floor(intDiff / 60) - (day * 24 * 60) - (hour * 60);
			second = Math.floor(intDiff) - (day * 24 * 60 * 60) - (hour * 60 * 60) - (minute * 60);
		}
		if (hour   <= 9) hour   = '0' + hour;
		if (minute <= 9) minute = '0' + minute;
		if (second <= 9) second = '0' + second;
		$('#day_show').html(day);
		$('#hour_show').html(hour);
		$('#minute_show').html(minute);
		$('#second_show').html(second);
		intDiff--;
		}, 1000);
	}
	timer(intDiff);

	// php后台注意2***********
	// 用户输入订购信息
	$('.reserve-btn').on('click', '.confirm', function() {
		var name  = $(".reserve-form .name").val(),
			phone = $(".reserve-form .phone").val(),
			mobileReg  = /^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9]|17[0|1|2|3|5|6|7|8|9])\d{8}$/,
			numberReg  = /^[0-9]+.?[0-9]*$/; 

		if (name == '') {
			layer.msg('请输入您的姓名！', {time:1000});
			return false
		}
		if (name.length <= 1) {
			layer.msg('姓名不能少于1位字符', {time:1000});
			return false
		}
		if (numberReg.test(name)) {
			layer.msg('请您输入非数字的个人姓名', {time:1000});
			return false
		}
		if (phone == '') {
			layer.msg('请输入您的手机号码！', {time:1000});
			return false
		}
		if (phone.length < 11) {
			layer.msg('手机号码不能少于11位数字', {time:1000});
			return false
		}
		if (!mobileReg.test(phone)) {
			layer.msg('您的手机格式错误！<br/>请输入11位数移动电话号码', {time:1000});
			return false
		}
		if (name !== '' && phone !== '' && name.length > 1 && phone.length == 11) {
			
			// 加载loading
			var index = layer.load(2, {
				shade: [0.1,'#fff']
			});

			setTimeout(function() {

				layer.close(index);
				layer.msg('表单验证通过测试！ajax后由后台获取', {time:1000});
				// window.location.href = 'game.html'
				console.log(name);
                console.log(phone)
				$.ajax({
					url:'./AddChuLi.php',
					type:'POST',
					dataType: "json",
					data: 'customer_name=' + name + '&customer_phone=' + phone,
					success: function(json){
						if(json.ret==1){
							layer.msg('发送成功');
							window.location.href = 'game.html'
							
						}else{
							layer.msg('数据异常，请重新登陆！');
						}
					}
				});


			},1000);
		}
	});
});